<?php
class Book {
	private $id;
	private $title;
	private $author;
	private $averagePoints;
	private $visits;
	private $price;
	private $amount;
	private $section;
	private $text;
	private $picture;
	
	/*
	 * Constructor
	 */
	function __construct($id){
		$this->id=$id;
		$this->recoveryfromfile($id);
	}
//	function __construct($id,$name,$author,$averagePoints, $visits, $price,$amount,$picture) {
//		$this->id=$id;
//		$this->name=$name;
//		$this->author=$author;
//		$this->averagePoints=$averagePoints;
//		$this->visits=$visits;
//		$this->price=$price;
//		$this->amount=$amount;
//		$this->picture=$picture;
//		
//	}
	
	private function recoveryfromfile($id){
		$serverpath=$_SERVER['DOCUMENT_ROOT'];
		$filename=$serverpath."/files/Book/".$id.".txt";
		$file = fopen("$filename","r");
		$line = fgets($file);
		$info = explode('|',$line);
		$this->set_title($info[0]);
		$this->set_author($info[1]);
		$this->set_averagePoints($info[2]);
		$this->set_visits($info[3]);
		$this->set_price($info[4]);
		$this->set_amount($info[5]);
		$this->set_section($info[6]);
		$this->set_text($info[7]);
		$this->set_picture($info[8]);
		fclose($file);
	}
	
	public function savetofile($id){
		$serverpath=$_SERVER['DOCUMENT_ROOT'];
		$filename=$serverpath.'/files/Book/'.$id.'.txt';
		$file = fopen($filename,"w");
		$Stringline = $this->title.'|'.$this->author.'|'.$this->averagePoints.'|'.$this->visits.'|'.
		$this->price.'|'.$this->amount.'|'.$this->section.'|'.$this->text.'|'.$this->picture;
		fwrite($file,$Stringline);
		fclose($file);
	}
	
	public function get_id(){
		return $this->id;
	}
	
	public function set_id(){
		return $this->id;
	}
	
	public function get_title(){
		return $this->title;
	}
	public function set_title($title){
		$this->title=$title;
	}
	
	public function get_author(){
		return $this->author;
	}
	public function set_author($author){
		$this->author=$author;
	}
	
	public function get_averagePoints(){
		return $this->averagePoints;
	}
	public function set_averagePoints($averagePoints){
		$this->averagePoints=$averagePoints;
	}
	
	public function get_visits(){
		return $this->visits;
	}
	public function set_visits($visits){
		$this->visits=$visits;
	}
	
	public function get_price(){
		return $this->price;
	}
	public function set_price($price){
		$this->price=$price;
	}

	public function get_amount(){
		return $this->amount;
	}
	public function set_amount($amount){
		$this->amount=$amount;
	}
	
	public function get_section(){
		return $this->section;
	}
	public function set_section($section){
		$this->section=$section;
	}
	
	public function get_text(){
		return $this->text;
	}
	public function set_text($text){
		$this->text=$text;
	}
	
	public function get_picture(){
		return $this->picture;
	}
	public function set_picture($picture){
		$this->picture=$picture;
	}
	
}
?>